package com.example.httpdemo.controller;

import com.example.common.global.BaseController;
import com.example.common.global.CommonResponse;
import com.example.httpdemo.pojo.DoorVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author Aaron
 * @since 2021/9/6 19:25
 * <p>描述：</p>
 */
@RestController
@RequestMapping("/valid")
public class ValidController extends BaseController {

    @RequestMapping("/door")
    public CommonResponse<?> door(@Valid DoorVO doorVO) {
        // 参数未校验通过时，抛出 BindException 异常

        int a = 1 / 0;
        return success(doorVO, "valid success.");
    }

    @RequestMapping("/doorValid")
    public CommonResponse<?> valid(@Valid DoorVO doorVO) {
        return success(doorVO, "valid success.");
    }

    @RequestMapping("/doorValidated")
    public CommonResponse<?> validated(@Validated DoorVO doorVO) {
        return success(doorVO, "valid success.");
    }

    @RequestMapping("/doorValidRequestBody")
    public CommonResponse<?> doorValidRequestBody(@Valid @RequestBody DoorVO doorVO) {
        return success(doorVO, "valid success.");
    }

    @RequestMapping("/doorValidatedRequestBody")
    public CommonResponse<?> doorValidatedRequestBody(@Validated @RequestBody DoorVO doorVO) {
        return success(doorVO, "valid success.");
    }

}
